package com.gzck.gzck_verson2.service.impl;

import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gzck.gzck_verson2.pojo.GSensorInfo;
import com.gzck.gzck_verson2.mapper.GSensorInfoMapper;
import com.gzck.gzck_verson2.pojo.GSensorParaInfo;
import com.gzck.gzck_verson2.pojo.vo.AddSensorVO;
import com.gzck.gzck_verson2.service.IGSensorInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.minio.Xml;
import org.apache.http.impl.auth.GGSSchemeBase;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 传感器信息/设备信息 服务实现类
 * </p>
 *
 * @author 任永辉
 * @since 2024-01-27
 */
@Service
public class GSensorInfoServiceImpl extends ServiceImpl<GSensorInfoMapper, GSensorInfo> implements IGSensorInfoService {

    /**
     * 添加传感器
     * 涉及到多张表，逻辑复杂，需要分步处理
     *
     * @param sensorInfo
     */
    @Override
    public SaResult saveSensorInfo(AddSensorVO sensorInfo) {
        GSensorInfo gSensorInfo = sensorInfo.getGSensorInfo();
        List<GSensorParaInfo> sensorParaInfos = sensorInfo.getSensorParaInfos();
        //工程id和采集仪id假设前端做处理
        //添加传感器到数据库  已经表明传感器属于的采集仪
        String name = gSensorInfo.getName();
        if (gSensorInfo != null) {
            GSensorInfo one = this.getOne(
                    Wrappers.lambdaQuery(GSensorInfo.class)
                            .eq(GSensorInfo::getName, name)
            );
            if (ObjectUtil.isEmpty(one)) {
                //没有重复
                this.save(gSensorInfo);
            } else {
                return SaResult.error("存在重复的传感器名称");
            }
        }
        //在查询出来，获得对应的id
        Long sensorId = this.getOne(
                Wrappers.lambdaQuery(GSensorInfo.class)
                        .eq(GSensorInfo::getName, name)
        ).getId();

//        //处理测值的数据
//        //1.先进行参数补全
//        sensorParaInfos.stream().forEach(
//                x -> {
//                    x.setSensorId(sensorId);
//                    x.set
//                }
//        );
        return null;


    }
}
